package cn.wind.xboot.framework.sequence;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.StringRedisTemplate;

import java.util.Map;

/**
 * <p>Title: SequenceClient</p>
 * <p>Description: TODO</p>
 *
 * @author xukk
 * @version 1.0
 * @date 2018/8/15
 */
public class SequenceClient {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    public void popNumber(String key,Integer range){
        HashOperations<String, String, String> hashOperations=stringRedisTemplate.opsForHash();
        Map<String,String > map=hashOperations.entries(key);
        Long curNumber=Long.valueOf(map.getOrDefault("cur","0"));
        Long maxNumber=Long.valueOf(map.getOrDefault("max","1000"));
        hashOperations.increment(key,"cur",range);

    }
}
